{extend name="adminblue/base" /}
{block name="resources"/}
<script src="ADMIN_JS/art_dialog.source.js"></script>
<script src="ADMIN_JS/iframe_tools.source.js"></script>
<script src="ADMIN_JS/material_managedialog.js"></script>
<link rel="stylesheet" type="text/css" href="ADMIN_CSS/defau.css">
<style>
label {float:left;text-align: left;font-size: 12px;padding:0 10px;overflow:hidden;color:#666;font-weight: normal;line-height: 32px;margin-bottom:0}
label input[type="radio"]{margin: 0 5px 0 0;} 
</style>
{/block}
{block name="main"}
<div class="set-style">
	<dl>
		<dt><span class="color-red">*</span>名称：</dt>
		<dd>
			<input id="link_title" type="text" value="{$link_info.link_title}" class="input-common" />
			<p class="error">请输入名称</p>
		</dd>
	</dl>
	<dl>
		<dt>图片：</dt>
		<dd>
			<div class="class-logo">
				<p>
					{if condition="$link_info.link_pic!=''"}
					<img id="imglink_pic" src="{:__IMG($link_info.link_pic)}">
					{else/}
					<img id="imglink_pic">
					{/if}
				</p>
			</div>
			<div class="upload-btn">
				<span>
					<input class="input-file" name="file_upload" id="uploadImg" type="file" onchange="imgUpload(this);">
					<input type="hidden" id="link_pic" value="{$link_info.link_pic}" />
				</span>
				<p><i class="fa fa-cloud-upload"></i>上传图片</p>
			</div>
			<p class="hint">
				<br> <span style="color: orange;">建议使用宽100像素-高100像素内的GIF或PNG透明图片；点击下方"提交"按钮后生效。</span>
			</p>
		</dd>
	</dl>
	<dl>
		<dt>是否新窗口打开:</dt>
		<dd>
			<label for="navigationtype1"><input type="radio" value="1" name="navigationtype" id="navigationtype1" {if condition="$link_info.is_blank eq 1"}checked="checked"{/if}/>是</label>
			<label for="navigationtype2"><input type="radio" value="2" name="navigationtype" id="navigationtype2" {if condition="$link_info.is_blank eq 2"}checked="checked"{/if}/>否</label>
		</dd>
	</dl>
	<dl>
		<dt>是否显示:</dt>
		<dd>
			<label for="showtype1"><input type="radio" value="1" name="showtype" id="showtype1" {if condition="$link_info.is_show eq 1"}checked="checked"{/if}/>是</label>
			<label for="showtype2"><input type="radio" value="2" name="showtype" id="showtype2" {if condition="$link_info.is_show eq 2"}checked="checked"{/if}/>否</label>
		</dd>
	</dl>
	
	<dl>
		<dt>链接地址:</dt>
		<dd>
			<p>
				<input id="link_url" type="text" value="{$link_info.link_url}" class="input-common" />
			</p>
			<p class="hint">用于网站搜索引擎的优化，关键字之间请用英文逗号分隔</p>
		</dd>
	</dl>
	<dl>
		<dt>排序:</dt>
		<dd>
			<p>
				<input id="link_sort" type="number" value="{$link_info.link_sort}" class="input-common" />
			</p>
		</dd>
	</dl>
	<dl>
		<dt></dt>
		<dd><button class="btn-common btn-big" onclick="setConfigAjax();">提交</button></dd>
	</dl>
</div>
<input type="hidden" value="{$link_info.link_id}" id="link_id"/>
<script src="__STATIC__/js/ajax_file_upload.js" type="text/javascript"></script>
<script src="__STATIC__/js/file_upload.js" type="text/javascript"></script>
<script>
//图片上传
function imgUpload(event) {
	var fileid = $(event).attr("id");
	var data = { 'file_path' : UPLOADCOMMON };
	uploadFile(fileid,data,function(res){
		if(res.code){
			$("#imglink_pic").attr("src",__IMG(res.data));
			$("#link_pic").val(res.data);
			showTip(res.message,"success");
		}else{
			showTip(res.message,"error");
		}
	});
}
function setConfigAjax() {
	var link_id = $("#link_id").val();
	var link_title = $("#link_title").val();
	var link_url = $("#link_url").val();
	var link_pic = $("#link_pic").val();
	var link_sort = $("#link_sort").val();
	var is_blank = $("input[name='navigationtype']:checked").val();
	var is_show = $("input[name='showtype']:checked").val();
	if(link_title.length == 0){
		$("#link_title").next(".error").show();
		return false;
	}else{
		$(".error").hide();
	}
	$.ajax({
		type : "post",
		url : "{:__URL('ADMIN_MAIN/config/updatelink')}",
		data : {
			'link_id' : link_id,
			'link_title' : link_title,
			'link_url' : link_url,
			'link_pic' : link_pic,
			'link_sort' : link_sort,
			'is_blank' : is_blank,
			'is_show' : is_show
		},
		success : function(data) {
			if (data["code"] > 0) {
				showMessage('success', data["message"],"{:__URL('ADMIN_MAIN/config/linklist')}");
			} else {
				showMessage('error', data["message"]);
			}
		}
	});
}
</script>
{/block}